import dayjs from 'dayjs'
import crypto from "crypto-js";
import {

	PWD_ENC_KEY

} from '@/utils/requestURL.js'

export function isMobile() {
	return !!navigator.userAgent.match(
		/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
	)
}

export function encryption(word) {
	let key = crypto.enc.Latin1.parse(PWD_ENC_KEY);
	let srcs = crypto.enc.Utf8.parse(word);
	let encrypted = crypto.AES.encrypt(srcs, key, {
		iv: key,
		mode: crypto.mode.CFB,
		padding: crypto.pad.NoPadding
	});
	return encrypted.toString()
}
// 解密
export function decrypt(ciphertext) {
	if(ciphertext == null) return null;
	let key = crypto.enc.Latin1.parse(PWD_ENC_KEY);
	const decrypted = crypto.AES.decrypt(ciphertext, key, {
		iv: key,
		mode: crypto.mode.CFB,
		padding: crypto.pad.NoPadding
	});
	return decrypted.toString(crypto.enc.Utf8);
}

export function plusZero(val) {
	return val < 10 ? `0${val}` : val
}


/**
 * @desc  格式化时间
 * @param {(number)} time 毫秒 
 * @param {string} format
 * @returns {string | null}
 */
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
	return dayjs(time).format(format)
}

export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
	return formatDateTime(date, format)
}

/**
 * @desc  函数节流
 * @param {Function} fn
 * @param {Number} wait
 * @returns {Function}
 */
export function throttle(fn, wait) {
	var context, args
	var previous = 0

	return function() {
		var now = +new Date()
		context = this
		args = arguments
		if (now - previous > wait) {
			fn.apply(context, args)
			previous = now
		}
	}
}

/**
 * @desc  函数防抖
 * @param {Function} func
 * @param {number} wait
 * @param {boolean} immediate
 * @return {*}
 */
export function debounce(method, wait = 500, immediate) {
	let timeout
	return function(...args) {
		let context = this
		if (timeout) {
			clearTimeout(timeout)
		}
		if (immediate) {
			let callNow = !timeout
			timeout = setTimeout(() => {
				timeout = null
			}, wait)
			if (callNow) {
				method.apply(context, args)
			}
		} else {
			timeout = setTimeout(() => {
				method.apply(context, args)
			}, wait)
		}
	}
}

// 深拷贝
export const deepClone = (obj) => {
	let result = Array.isArray(obj) ? [] : {};
	for (let key in obj) {
		if (obj.hasOwnProperty(key)) {
			if (obj[key] && typeof obj[key] === 'object') {
				result[key] = deepClone(obj[key]); // 递归复制
			} else {
				result[key] = obj[key];
			}
		}
	}
	return result;
}

// 判断对象中是否存在某个值
export const localkeyvalisexist = (keyname, json) => {
	if (!json || typeof(json) != "object" || typeof(json) == "undefined") return false;
	if (!json.hasOwnProperty(keyname) || json[keyname] == "" || json[keyname] == "undefined") return false;
	return true;
}

// 将对象的形式换成 a=123,b=456
export const keyArrfangfa = (data) => {
	let keyArr = Object.keys(data).sort(function(a, b) {
		return data[a] - data[b]; //升序
	});
	let strParam = ""
	for (let key of keyArr) { //遍历键数组
		strParam += ("," + key + "=" + data[key]);
	}
	return strParam
}



// 时间转秒 12:00 默认是
export const timeCycle = (time, type = 'HH:MM') => {
	if (type == 'HH:MM') {
		let sum = 0
		let arr = time.split(':');
		sum += arr[0] * 60 * 60
		sum += arr[1] * 60
		return sum
	}
}

// 时 分 秒转 秒
export const HTimeCycle = (time) => {
	let sum = 0
	sum += parseInt(time[0] * 60 * 60)
	sum += parseInt(time[1] * 60)
	sum += parseInt(time[2])
	return sum
}

// 秒 转 时间
export const secondToTime = (value) => {
	var secondTime = parseInt(value) // 秒
	var minuteTime = 0 // 分
	var hourTime = 0 // 小时

	var result = ''
	if (value < 60) {
		result = secondTime + '秒'
	} else {
		if (secondTime >= 60) { // 如果秒数大于60，将秒数转换成整数
			// 获取分钟，除以60取整数，得到整数分钟
			minuteTime = parseInt(secondTime / 60)
			// 获取秒数，秒数取佘，得到整数秒数
			secondTime = parseInt(secondTime % 60)
			// 如果分钟大于60，将分钟转换成小时
			if (minuteTime >= 60) {
				// 获取小时，获取分钟除以60，得到整数小时
				hourTime = parseInt(minuteTime / 60)
				// 获取小时后取佘的分，获取分钟除以60取佘的分
				minuteTime = parseInt(minuteTime % 60)
				if (hourTime >= 24) {

					// 获取小时后取余小时，获取分钟除以24取余的分；
					hourTime = parseInt(hourTime % 24)
				}
			}
		}
		if (secondTime > 0) {
			secondTime = parseInt(secondTime) >= 10 ? secondTime : '0' + secondTime
			result = '' + secondTime + '秒'
		}
		if (minuteTime > 0) {
			minuteTime = parseInt(minuteTime) >= 10 ? minuteTime : '0' + minuteTime
			result = '' + minuteTime + '分' + result
		}
		if (hourTime > 0) {
			result = '' + parseInt(hourTime) + '小时' + result
		}

	}
	return result

}
// 秒 转 时间
export const secondToTime2 = (value) => {
	var secondTime = parseInt(value) // 秒
	var minuteTime = 0 // 分
	var hourTime = 0 // 小时

	if (value > 60) {
		if (secondTime >= 60) { // 如果秒数大于60，将秒数转换成整数
			// 获取分钟，除以60取整数，得到整数分钟
			minuteTime = parseInt(secondTime / 60)
			// 获取秒数，秒数取佘，得到整数秒数
			secondTime = parseInt(secondTime % 60)
			// 如果分钟大于60，将分钟转换成小时
			if (minuteTime >= 60) {
				// 获取小时，获取分钟除以60，得到整数小时
				hourTime = parseInt(minuteTime / 60)
				// 获取小时后取佘的分，获取分钟除以60取佘的分
				minuteTime = parseInt(minuteTime % 60)
				if (hourTime >= 24) {

					// 获取小时后取余小时，获取分钟除以24取余的分；
					hourTime = parseInt(hourTime % 24)
				}
			}
		}

	}
	return [hourTime, minuteTime, secondTime]

}
export const timeStamp = () => {
	return new Date().getTime()
}
export const createNonceStr = () => {
	var str = "",
		range = 8, //min
		arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E',
			'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
		];

	// // 随机产生
	// if (true) {
	//   range = Math.round(Math.random() * (36 - 20)) + 20;
	// }
	for (var i = 0; i < range; i++) {
		var pos = Math.round(Math.random() * (arr.length - 1));
		str += arr[pos];
	}
	return str;
}





export const stringToHex = (str) => {
	var val = "";
	for (var i = 0; i < str.length; i++) {
		if (val == "")
			val = str.charCodeAt(i).toString(16);
		else
			val += str.charCodeAt(i).toString(16);
	}
	return val;
}

//16进制转换成字符串
export const hexToString = (hex) => {
	var arr = hex.split("");
	var out = "";
	for (var i = 0; i < arr.length / 2; i++) {
		var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1];
		var charValue = String.fromCharCode(tmp);
		out += charValue;
	}
	return out;
}

//ArrayBuffer转16进度字符串示例
export const ab2hex = (buffer) => {
	const hexArr = Array.prototype.map.call(
		new Uint8Array(buffer),
		function(bit) {
			return ('00' + bit.toString(16)).slice(-2);
		}
	)
	return hexArr.join('');
}

export const stringToCmdBuffer = (inputstr) => {
	return new Uint8Array(inputstr.match(/[\da-f]{2}/gi).map(function(h) {
		return parseInt(h, 16)
	})).buffer
}

export const string2buffer = (str) => {
	let val = "";
	if (!str) return;
	let length = str.length;
	let index = 0;
	let array = [];
	while (index < length) {
		array.push(str.substring(index, index + 2));
		index = index + 2;
	}
	val = array.join(",");
	// 将16进制转化为ArrayBuffer
	return new Uint8Array(val.match(/[\da-f]{2}/gi).map(function(h) {
		return parseInt(h, 16);
	})).buffer
}
export const concatenation = (str) => {
	var val = "";
	var rule = /.*[\u4e00-\u9fa5]+.*$/
	for (var i = 0; i < str.length; i++) {
		if (val == "" && rule.test(str[i]) === false) {
			val = str.charCodeAt(i).toString(16);
		} else if (val == "" && rule.test(str[i])) {
			val = encodeURI(str[i]).replace(/%/gm, '')
		} else if (rule.test(str[i]) === false) {
			val += str.charCodeAt(i).toString(16);
		} else if (rule.test(str[i])) {
			val += encodeURI(str[i]).replace(/%/gm, '')
		}
	}
	return val;
}
export const upperCase = (str) => {
	let arr = str.split("");
	let newStr = "";
	// 通过数组的forEach方法来遍历数组
	arr.forEach(function(value) {
		if (value >= 'a' && value <= 'z')
			newStr += value.toUpperCase();
		else
			newStr += value;
	});
	return newStr;
}
export const stringToArrayBuffer = (str) => {
	var bytes = new Array();
	var len, c;
	len = str.length;
	for (var i = 0; i < len; i++) {
		c = str.charCodeAt(i);
		if (c >= 0x010000 && c <= 0x10FFFF) {
			bytes.push(((c >> 18) & 0x07) | 0xF0);
			bytes.push(((c >> 12) & 0x3F) | 0x80);
			bytes.push(((c >> 6) & 0x3F) | 0x80);
			bytes.push((c & 0x3F) | 0x80);
		} else if (c >= 0x000800 && c <= 0x00FFFF) {
			bytes.push(((c >> 12) & 0x0F) | 0xE0);
			bytes.push(((c >> 6) & 0x3F) | 0x80);
			bytes.push((c & 0x3F) | 0x80);
		} else if (c >= 0x000080 && c <= 0x0007FF) {
			bytes.push(((c >> 6) & 0x1F) | 0xC0);
			bytes.push((c & 0x3F) | 0x80);
		} else {
			bytes.push(c & 0xFF);
		}
	}
	var array = new Int8Array(bytes.length);
	for (var i in bytes) {
		array[i] = bytes[i];
	}
	return array.buffer;
}

export const stringToByte = (str) => {
	var len, c;
	len = str.length;
	var bytes = [];
	for (var i = 0; i < len; i++) {
		c = str.charCodeAt(i);
		if (c >= 0x010000 && c <= 0x10FFFF) {
			bytes.push(((c >> 18) & 0x07) | 0xF0);
			bytes.push(((c >> 12) & 0x3F) | 0x80);
			bytes.push(((c >> 6) & 0x3F) | 0x80);
			bytes.push((c & 0x3F) | 0x80);
		} else if (c >= 0x000800 && c <= 0x00FFFF) {
			bytes.push(((c >> 12) & 0x0F) | 0xE0);
			bytes.push(((c >> 6) & 0x3F) | 0x80);
			bytes.push((c & 0x3F) | 0x80);
		} else if (c >= 0x000080 && c <= 0x0007FF) {
			bytes.push(((c >> 6) & 0x1F) | 0xC0);
			bytes.push((c & 0x3F) | 0x80);
		} else {
			bytes.push(c & 0xFF);
		}
	}
	return new Int8Array(bytes);
}



/* 用户sql
let obj = {
	a:'111',
	b:'222'
}
"'111','222'"
*/
export const setObjSql = (obj) => {
	let newObj = {}
	for (let key in obj) {
		newObj[key] = `'${obj[key]}'`
		// `'${encryption(obj[key])}'`
		// `'${obj[key]}'`
	}
	return Object.values(newObj).join(',')
}
export const obj2str_sql = (obj) => {
	/**
	 * @param {obj}  需要转换的对象
	 * @return {string} 返回key1='val1',key2='val2'....格式  如果有id字段  会把对象的id字段删除
	 */
	let newObj = deepClone(obj)
	// for (const key in newObj) {
	// 	newObj[key] = encryption(newObj[key])
	// }

	if (newObj.id) delete newObj.id;
	let w = Object.entries(newObj);
	w.forEach((v, i) => {
		w[i] = v.join('=\'') + '\''
	});
	return w.join(',');
}
//获取当前年月日
export const getNewYMD = () => {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1; //得到月份
	var date = now.getDate(); //得到日期
	if (month < 10) {
		month = '0' + month
	}
	if (date < 10) {
		date = '0' + date
	}
	return year + "-" + month + "-" + date;
}
export const getrentCode = () => {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1; //得到月份
	var date = now.getDate(); //得到日期
	if (month < 10) {
		month = '0' + month
	}
	if (date < 10) {
		date = '0' + date
	}
	let ymd = year + "" + month + "" + date;
	return 'RT' + ymd + createNonceStr()
}
export const getWeekDate = () => {
	const now = dayjs()
	const startOfWeek = now.startOf('week');
	const endOfWeek = now.endOf('week');
	return {
		startDate: dayjs(startOfWeek).format('YYYY-MM-DD'),
		endDate: dayjs(endOfWeek).add(1, 'day').format('YYYY-MM-DD'),
	}
}

export const getMonthDate = () => {
	const now = dayjs()
	const startOfWeek = now.startOf('month');
	const endOfWeek = now.endOf('month');
	return {
		startDate: dayjs(startOfWeek).format('YYYY-MM-DD'),
		endDate: dayjs(endOfWeek).add(1, 'day').format('YYYY-MM-DD'),
	}
}

export const getDayDate = () => {
	const now = dayjs()
	const startOfWeek = now.startOf('day');
	const endOfWeek = now.endOf('day');
	return {
		startDate: dayjs(startOfWeek).format('YYYY-MM-DD'),
		endDate: dayjs(endOfWeek).add(1, 'day').format('YYYY-MM-DD'),
	}
}

export const getNewYMDHMS = () => {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1; //得到月份
	var date = now.getDate(); //得到日期
	var h = now.getHours(); //获取时
	var m = now.getMinutes(); //获取分
	var s = now.getSeconds(); //获取秒
	if (month < 10) {
		month = '0' + month
	}
	if (date < 10) {
		date = '0' + date
	}

	if (h < 10) {
		h = '0' + h
	}

	if (m < 10) {
		m = '0' + m
	}

	if (s < 10) {
		s = '0' + s
	}

	return `${year}-${month}-${date} ${h}:${m}:${s}`
}


export const getNewYMDSql = () => {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1; //得到月份
	var date = now.getDate(); //得到日期
	if (month < 10) {
		month = '0' + month
	}
	if (date < 10) {
		date = '0' + date
	}
	return year + "" + month + "" + date;
}
// 过滤对象中null undefined ''的对象
export const filteredObject = (obj) => {
	return Object.entries(obj).reduce((acc, [key, value]) => {
		if (value !== null && value !== undefined && value !== '') {
			acc[key] = value;
		}
		return acc;
	}, {});

}

// 产品的PID转为设备MAC地址 转16进制 不足12位，前面0补
export const pidToMAC = (pid) => {
	let mac = Number(pid).toString(16).toUpperCase()
	let macLen = mac.length;
	if (macLen < 12) {
		let supLen = 12 - macLen;
		let sup = '';
		for (let i = 0; i < supLen; i++) {
			sup += '0'
		}

		mac = sup + mac;
	}
	return mac
}

// 将mac地址 00000E485E8C  变为 8c:5E:48:0E:00:00
export const formatHexString = (hexString) => {
	// 验证输入字符串长度是否为偶数
	if (hexString.length % 2 !== 0) {
		throw new Error('Input hex string must have an even number of characters');
	}

	// 初始化结果数组
	var result = [];

	// 遍历每两个字符
	for (var i = 0; i < hexString.length; i += 2) {
		// 提取每两个字符的子串并反转
		var subStr = hexString.substr(i, 2).split('').join('');
		// 将反转后的子串添加到结果数组中
		result.unshift(subStr);
	}

	// 使用冒号连接结果数组中的子串
	return result.join('').toUpperCase(); // 转换为大写并返回
}
// 解析设备发出的信息
export const dataTran = (str) => {


	let strlen = parseInt(str.slice(0, 2), 16) * 2 //长度
	let data = str.slice(2, 2 + strlen) //数据
	let perch = data.slice(0, 2) //顺序 ff
	let order = parseInt(data.slice(2, 4), 16) //命令 
	let mac = data.slice(4, 16) //mac地址 f1f2f3f4f5f6
	let littleNum = data.slice(16, data.length)

	return {
		order,
		mac,
		littleNum
	}
	console.log(strlen, data, order, mac);

	// function littleEndianToInt(bytes) {
	// 	let value = 0;
	// 	for (let i = 0; i < 4; i++) {
	// 		value |= (bytes[i] << (i * 8));
	// 	}
	// 	return value;
	// }

	// // 测试函数
	// function main(littleEndianBytes) {


	// 	// let littleEndianBytes = [0x30, 0x75];

	// 	console.log("Little endian bytes:");
	// 	littleEndianBytes.forEach(byte => {
	// 		console.log(byte.toString(16).padStart(2, '0'));
	// 	});

	// 	const convertedValue = littleEndianToInt(littleEndianBytes);
	// 	console.log("Converted value:", convertedValue);
	// }

	// let strlen = parseInt(str.slice(0, 2), 16) * 2 //长度
	// let data = str.slice(2, 2 + strlen) //数据
	// let perch = data.slice(0, 2) //顺序 ff
	// let order = parseInt(data.slice(2, 4), 16) //命令 
	// let mac = data.slice(4, 16) //mac地址 f1f2f3f4f5f6
	// let num = parseInt(data.slice(16, data.length), 16) //数字 50

	// return {
	// 	order,
	// 	mac,
	// 	num
	// }
	// console.log(strlen, data, order, mac, num);
}
// 每隔两个加上一个: 
export const addColonEveryTwoChars = (str) => {
	// 如果字符串长度小于2，则直接返回原字符串
	if (str.length < 2) {
		return str;
	}
	// 使用reduce和substring方法来处理字符串
	return str.split('').reduce((acc, curr, index, arr) => {
		// 在除了最后一个MWK 素之前的每两个MWK 素间加上冒号
		if (index !== arr.length - 1 && (index + 1) % 2 === 0) {
			return acc + curr + ':';
		}
		return acc + curr;
	}, '');
}

// 分转换为MWK 
export const moneyTran = (m) => {
	return (m / 100).toFixed(2)
}
// 判断数据上报的命令是否是属于 命令 order 252
export const repetitionData = (arr, order) => {
	return arr.find(item => {
		return parseInt(item.msg.slice(4, 6), 16) == order
	})
}

export const repetitionDataFil = (arr, order) => {
	return arr.filter(item => {
		return parseInt(item.msg.slice(4, 6), 16) == order
	})
}

// 判断数据上报的命令是否是属于 命令 order 252 并且mac地址是传递进来的 Mac 设备的produtId
export const repetitionDataMac = (arr, order, Mac) => {
	return arr.find(item => {
		return parseInt(item.msg.slice(4, 6), 16) == order && parseInt(item.mac.split(':').join(''), 16) == Mac
	})
}

// 处理盘点数据 
export const repetitionCheck = (arr, order) => {
	return arr.filter(item => {
		return parseInt(item.msg.slice(4, 6), 16) == order
	})

}
// 处理群回复 还灯数据
export const mulDataDevice = (str) => {
	// str = 1CFFFCF6F5F4F3F2F1887602712C017364006E1E008507007C6E006605
	//      18 FFFCF6F5F4F3F2F1 6FF000 6C1400 6764 7C3C00 7B3175 8700
	//      18 fffc5de9102f3458 6f0000 840000 6623 7c0000 7b3075 870000000000000000000000000000000000000000000000000000000000000000000000000000
	//  1c fffcffffffffffff 880000 710000 7300 006e00 008600 007c 77036651000000000000000000000000000000000000000000000000000000000000000000
	//  1C FFFCF6F5F4F3F2F1 6FF000 6C1400 6764 7CC602 7B3175 8700
	let strLen = parseInt(str.slice(0, 2), 16) * 2 //长度

	let data = str.slice(2, strLen + 2); //FF FC F6F5F4F3F2F1 887602 712C01 736400 6E1E00 850700 7C6E00 6605
	let order = parseInt(data.slice(2, 4), 16) //252 接收命令

	let appMac = data.slice(4, 16); //手机mac
	let dataList = data.slice(16, 56);
	let list = []
	let keys = ''
	let orderList = []
	let fre = 1
	while (dataList.length > 0) {
		fre++;
		if (fre > 20) { //最多循环20次
			return
		}

		let item = parseInt(dataList.substr(0, 2), 16)
		keys += dataList.substr(0, 2)
		if (item == 111 || item == 132 || item == 124 || item == 123 || item == 136 || item == 113 || item == 115 ||
			item == 110 || item == 133 || item == 134) {


			orderList.push({
				order: parseInt(dataList.substr(0, 2), 16),
				data: parseInt(dataList.slice(4, 6) + dataList.slice(2, 4), 16)
			})
			dataList = dataList.substring(6);

		} else if (item == 103 || item == 135 || item == 102) {

			orderList.push({
				order: parseInt(dataList.substr(0, 2), 16),
				data: parseInt(dataList.slice(2, 4), 16)
			})
			dataList = dataList.substring(4);
		}
	}

	// {
	// 	data:630, 分钟
	// 	order:136总亮灯时间
	// },
	// {
	// 	data:300,
	// 	order:113 三档亮灯时间
	// },
	// {
	// 	data:100,
	// 	order:115 一档亮灯时间
	// },
	// {
	// 	data:30,
	// 	order:110 充电时间
	// },
	// {
	// 	data:7,
	// 	order:133 usb放电能量
	// },
	// {
	// 	data:110,
	// 	order:124 剩余时间
	// },
	// {
	// 	data:5, 5%
	// 	order:102 上报电量
	// }

	return {
		order, //252 命令
		appMac, //手机mac
		orderList, //命令和数据集合
		keys, //命令集
	}
}

// 处理同步 租赁 归还 逾期 数据
export const setSyncDevice = (arr) => {
	// 转换后的二维数组
	var arrayTwo = Object.values(arr.reduce((res, item) => {
		res[item.productId] ? res[item.productId].push(item) : res[item.productId] = [item];
		return res;
	}, {}));
	console.log(arrayTwo)

	let syncArr = []
	arrayTwo.forEach(item => {
		let len = item.length
		let newObj = item[len - 1]
		console.log(len, newObj);
		let syncObj = {
			backDtos: [],
			rentDtos: [],
			overDtos: [],
			counter: newObj.counter + '',
			currProp: JSON.parse(newObj.currProp),

			pid: newObj.productId,

			rsAccount: newObj.customerAccount,
			stockStatus: newObj.leaseStatus + '',
		}
		console.log(syncObj, item);
		item.forEach(ele => {
			if (ele.backDtos != 'null') {
				let backDto = JSON.parse(ele.backDtos);
				backDto.rentCode = ele.rentCode;
				backDto.rentInterval = ele.leaseDay + '';
				backDto.rentPrice = ele.leasePrice + '';

				syncObj.backDtos.push(backDto)
			}
			if (ele.rentDtos != 'null') {
				let rentDto = JSON.parse(ele.rentDtos);
				rentDto.rentCode = ele.rentCode;
				rentDto.customerAccountUse = ele.customerAccount;
				rentDto.rentCode = ele.rentCode;
				// rentDto.rentDeposit = ele.agencySecurityDeposit; //设备的押金
				rentDto.rentInitInterval = ele.leaseDay + '';
				rentDto.rentInitPrice = ele.leasePrice + '';

				syncObj.rentDtos.push(rentDto)
			}
			if (ele.overTime != 'null') {
				let overDto = {
					createTime: ele.overTime,
					overInterval: ele.overdueDay + '',
					overLevel: ele.remind + '',
					rentCode: ele.rentCode,
				}
				let history = ele.history == 'null' ? [] : JSON.parse(ele.history)
				history.forEach((hisItem, hisIndex) => {
					if (hisIndex == 0) {
						overDto.overTrackOne = {
							"backExpect": hisItem.returnTime,
							"createTime": hisItem.createTime || '',
							"details": hisItem.details,
							"overReason": hisItem.overdueReason,
						}
					} else if (hisIndex == 1) {
						overDto.overTrackTwo = {
							"backExpect": hisItem.returnTime,
							"createTime": hisItem.createTime || '',
							"details": hisItem.details,
							"overReason": hisItem.overdueReason,
						}
					} else if (hisIndex == 2) {
						overDto.overTrackThree = {
							"backExpect": hisItem.returnTime,
							"createTime": hisItem.createTime || '',
							"details": hisItem.details,
							"overReason": hisItem.overdueReason,
						}
					}
				})
				syncObj.overDtos.push(overDto)

			}
		})

		console.log(syncObj);
		syncArr.push(syncObj)
	})
	return syncArr
}

export const isBlueOpne = () => {
	uni.openBluetoothAdapter({
		fail() {
			uni.showToast({
				title: 'Bluetooth is off',
				icon: 'none'
			})
			return false
		},
	})
}